#!/bin/bash
usage() {
    echo "Usage: verify-repo.sh repo-file"
    echo "If successful, verified file without armor is sent to stdout"
    echo "Otherwise, error code is set to non-zero"
}

APT_KEYRING=/etc/apt/trusted.gpg
DEVSCRIPT=$HOME/.devscripts

if [ -r "$DEVSCRIPT" ]; then
    . "$DEVSCRIPT"
fi

REPO_FILE="$1"

if [ -z "$REPO_FILE" ]; then
    usage
    exit 1
fi

if [ "$REPO_FILE" = "-" ]; then
    REPO_FILE="/dev/stdin"
fi

gpg --keyring "$APT_KEYRING" --batch -o -  "$REPO_FILE"
#interesting options: --with-colons --enable-progress-filter 

RESULT=$?
if [ $RESULT -ne 0 ]; then
    exit $RESULT
fi
exit 0
